package boun.swe.bob.service;


import boun.swe.bob.entities.User;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: ememory
 * Date: 27.Ara.2010
 * Time: 18:01:12
 * To change this template use File | Settings | File Templates.
 */

public class UserGroupController extends BaseController {
    @RequestMapping(method = RequestMethod.GET)
        public ModelAndView showPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
            Map<String, Object> myModel = Maps.newHashMap();
            //myModel.put("user", userDao.findByPrimaryKey(getLoggedInUser(httpServletRequest).getUserId()));
            String wantedUserId = httpServletRequest.getParameter("wantedUserId");
            User usr;
            if(Strings.isNullOrEmpty(wantedUserId))
            {
                usr = userDao.findByPrimaryKey(getLoggedInUser(httpServletRequest).getUserId());
                myModel.put("himself",true);
            }
            else
            {
                usr=userDao.findByPrimaryKey(Integer.parseInt(wantedUserId));
            }
            myModel.put("user",usr);
            myModel.put("userGroups",usr.getGroups());
            return new ModelAndView("user_groups", "model", myModel);
        }
}